/*
 * Copyright 2008 Andrej Herich
 * 
 * http://azetclient.yw.sk/
 * http://azetclient.googlecode.com/
 * 
 * This file is part of AzetClient.
 * 
 * AzetClient is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * AzetClient is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with AzetClient.  If not, see <http://www.gnu.org/licenses/>.
 */

package sk.yw.azetclient.model;

import java.util.Date;
import java.util.Locale;
import sk.yw.azetclient.Main;

/**
 *
 * @author error216
 */
public class Buddy implements Comparable<Buddy> {
    
    public enum Status { CHATTING, ONLINE, OFFLINE }
    public enum Gender { MALE, FEMALE }
    
    private int id = 0;
    private String name;
    private String alias;
    private Gender gender;
    private int age;
    private String location;
    private Date lastLogin;
    private Status status;
    private String room;
    private int roomNo;
    
    /** Creates a new instance of Buddy */
    public Buddy() {
    }
    
    @Override
    public synchronized boolean equals(Object obj) {
        if (obj instanceof Buddy) {
            Buddy buddy = (Buddy) obj;
            if (name != null && buddy.getName() != null) {
                return name.equalsIgnoreCase(buddy.getName());
            } else {
                return false;
            }
            
        } else {
            return false;
        }
    }
    
    @Override
    public synchronized int hashCode() {
        if (name != null) {
            return name.toLowerCase(Locale.ENGLISH).hashCode();
        } else {
            return 0;
        }
    }

    public synchronized int compareTo(Buddy buddy) {
        if (buddy == null)
            throw new IllegalArgumentException("Null pointer in buddy");
        
        if (name == null)
            throw new IllegalStateException("Name is null");
        
        if (buddy.getName() == null)
            throw new IllegalArgumentException("Name of other buddy is null");
        
        return Main.SLOVAK_COLLATOR.compare(getVisualName(),
                buddy.getVisualName());
    }

    public synchronized int getId() {
        return id;
    }

    public synchronized void setId(int id) {
        this.id = id;
    }

    public synchronized String getName() {
        return name;
    }

    public synchronized void setName(String name) {
        this.name = name;
    }

    public synchronized String getAlias() {
        return alias;
    }

    public synchronized void setAlias(String alias) {
        this.alias = alias;
    }

    public synchronized Gender getGender() {
        return gender;
    }

    public synchronized void setGender(Gender gender) {
        this.gender = gender;
    }

    public synchronized int getAge() {
        return age;
    }

    public synchronized void setAge(int age) {
        this.age = age;
    }

    public synchronized String getLocation() {
        return location;
    }

    public synchronized void setLocation(String location) {
        this.location = location;
    }

    public synchronized Date getLastLogin() {
        return lastLogin;
    }

    public synchronized void setLastLogin(Date lastLogin) {
        this.lastLogin = lastLogin;
    }

    public synchronized Status getStatus() {
        return status;
    }

    public synchronized void setStatus(Status status) {
        this.status = status;
    }

    public synchronized String getRoom() {
        return room;
    }

    public synchronized void setRoom(String room) {
        this.room = room;
    }

    public synchronized int getRoomNo() {
        return roomNo;
    }

    public synchronized void setRoomNo(int roomNo) {
        this.roomNo = roomNo;
    }
    
    public synchronized String getVisualName() {
        if (alias != null) return alias;
        return name;
    }
    
}
